package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.service.AlertRuleServicr;
import com.zzyl.vo.AlertRuleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 报警规则
 */
@RestController
@RequestMapping("/alert-rule")
public class AlertRuleController {

    @Autowired
    private AlertRuleServicr alertRuleServicr;

    /**
     * 新增报警规则
     * @param alertRuleDto
     * @return
     */
    @PostMapping("/create")
    public ResponseResult create(@RequestBody AlertRuleDto alertRuleDto){
        alertRuleServicr.create(alertRuleDto);
        return ResponseResult.success();
    }

    /**
     * 分页查询报警规则
     * @param pageNum
     * @param pageSize
     * @param alertRuleName
     * @param functionName
     * @param productKey
     * @return
     */
    @GetMapping("/get-page")
    public ResponseResult getPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "10")Integer pageSize,String alertRuleName,
                                  String functionName,String productKey){
        PageResponse<AlertRuleVo> response=alertRuleServicr.getPage(pageNum,pageSize,alertRuleName,functionName,productKey);
        return ResponseResult.success(response);
    }

    /**
     * 获取单个烟雾报警规则
     * @param id
     * @return
     */
    @GetMapping("/read/{id}")
    public ResponseResult read(@PathVariable Integer id){
        AlertRuleVo alertRuleVo=alertRuleServicr.read(id);
        return ResponseResult.success(alertRuleVo);
    }

    /**
     * 修改
     * @param alertRuleDto
     * @param id
     */
    @PutMapping("/update/{id}")
    public ResponseResult update(@RequestBody AlertRuleDto alertRuleDto,@PathVariable Integer id){
        alertRuleServicr.update(alertRuleDto,id);
        return ResponseResult.success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseResult delete(@PathVariable Integer id){
        alertRuleServicr.delete(id);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Integer id,@PathVariable Integer status){
        alertRuleServicr.updateStatus(id,status);
        return ResponseResult.success();
    }
}
